<?php
namespace app\controller;

use app\BaseController;


class Index extends BaseController
{

    function index(){
        return '<a style="display: block;padding-left: 24px;" href="/index.php/project/index">示例1：分步骤</a><a style="display: block;padding-left: 24px;padding-top: 12px" href="/index.php/user/index">示例2：有子表</a>';
    }

    /**
     * 上传文件
     */
    public function upload()
    {
        $data = [
            'file'        => $this->request->file('file'),
        ];
        $rule = [
            'file|文件' => "require|file|fileExt:docx,doc,gif,ico,icon,jpg,mp3,mp4,p12,pem,png,rar,jpeg,xlsx,xls,txt,zip,rar|fileSize:10240000",
        ];
        $this->validate($data, $rule);
        // 上传到本地服务器
        $savename = \think\facade\Filesystem::disk('public')->putFile( 'test_files', $data['file']);

        return json([
            'code'=>1,
            'msg'=>'上传成功',
            'data'=>[
                'url'=>'/storage/'.$savename
            ]
        ]);

    }
}
